package com.render;

import static org.lwjgl.opengl.GL11.glTranslatef;

import org.lwjgl.opengl.GL11;

import base.living.Entity;
import base.living.EntityUtil;
import base.render.RenderEntity;

import com.living.EntityPlayer;

public class RenderPlayer extends RenderEntity
{
	@Override
	public void onRender(Entity par1Entity)
	{
		EntityPlayer player = (EntityPlayer) par1Entity;

		int width = par1Entity.getBoundingBox().width;
		int height = par1Entity.getBoundingBox().height;

		GL11.glPushMatrix();
		{
			int footDistToOrig = (int) (width * 0.675F);

			glTranslatef((float) EntityUtil.distXToRot(par1Entity.getPosRot() + 90, footDistToOrig), (float) EntityUtil.distYToRot(par1Entity.getPosRot() + 90, footDistToOrig), 0F);
			glTranslatef((float) EntityUtil.distXToRot(par1Entity.getPosRot(), player.getSwingProgress()), (float) EntityUtil.distYToRot(par1Entity.getPosRot(), player.getSwingProgress()), 0F);

			glTranslatef(par1Entity.getPosX(), par1Entity.getPosY(), 0);
			drawWithRotation(par1Entity.getPosRot() + 90);
			glTranslatef(-par1Entity.getPosX(), -par1Entity.getPosY(), 0);

			drawWithColor(0x4D3F2A);
			drawCenteredBox(par1Entity.getPosX(), par1Entity.getPosY(), (int) (width * 0.6F), (int) (height * 0.8F));
		}
		GL11.glPopMatrix();

		GL11.glPushMatrix();
		{
			int footDistToOrig = (int) (width * 0.675F);

			glTranslatef((float) EntityUtil.distXToRot(par1Entity.getPosRot() - 90, footDistToOrig), (float) EntityUtil.distYToRot(par1Entity.getPosRot() - 90, footDistToOrig), 0F);
			glTranslatef((float) EntityUtil.distXToRot(par1Entity.getPosRot(), -player.getSwingProgress()), (float) EntityUtil.distYToRot(par1Entity.getPosRot(), -player.getSwingProgress()), 0F);

			glTranslatef(par1Entity.getPosX(), par1Entity.getPosY(), 0);
			drawWithRotation(par1Entity.getPosRot() + 90);
			glTranslatef(-par1Entity.getPosX(), -par1Entity.getPosY(), 0);

			drawWithColor(0x4D3F2A);
			drawCenteredBox(par1Entity.getPosX(), par1Entity.getPosY(), (int) (width * 0.6F), (int) (height * 0.8F));
		}
		GL11.glPopMatrix();

		GL11.glPushMatrix();
		{
			glTranslatef(par1Entity.getPosX(), par1Entity.getPosY(), 0);
			drawWithRotation(par1Entity.getPosRot() + 90);
			glTranslatef(-par1Entity.getPosX(), -par1Entity.getPosY(), 0);

			drawWithColor(0x6C8235);
			drawCenteredBox(par1Entity.getPosX(), par1Entity.getPosY(), width * 2, (int) (height * 0.75F));
		}
		GL11.glPopMatrix();

		GL11.glPushMatrix();
		{
			glTranslatef(par1Entity.getPosX(), par1Entity.getPosY(), 0);
			drawWithRotation(((EntityPlayer) par1Entity).getHeadRot() + 90);
			glTranslatef(-par1Entity.getPosX(), -par1Entity.getPosY(), 0);

			drawWithColor(0xF5F4C6);
			drawCenteredBox(par1Entity.getPosX(), par1Entity.getPosY(), width, height);
		}
		GL11.glPopMatrix();
	}
}
